package uk.co.hephistocles.blobGame;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.flurry.android.FlurryAgent;

public class AndroidGame extends AndroidApplication implements IActivityRequestHandler {
		public  PapayaActivity testy = new PapayaActivity();
		View gameView;
		RelativeLayout layout;
		int viewId;
		 private PowerManager.WakeLock wl;
	       

        protected Handler handler = new Handler()
        {
            @Override
            public void handleMessage(Message msg) {
                
            }
        };
		
        public void onCreate (android.os.Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                FlurryAgent.enableAppCircle();
                FlurryAgent.onStartSession(this, "RV8Z7TLF3XAU6SK9NNT9");

                // Create the layout
                layout = new RelativeLayout(this);

                // Do the stuff that initialize() would do for you
                requestWindowFeature(Window.FEATURE_NO_TITLE);
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

                // Create the libgdx View
                gameView = initializeForView(new Game(this), false);
                viewId = gameView.getId();
                
                // Add the libgdx view
                layout.addView(gameView);

                // Hook it all up
                setContentView(layout);
                
                //Set up the wake lock
                PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

        }
        
        @Override
        public void onPause () {
        	super.onPause();
        	System.out.println("We finished tidily");
        	FlurryAgent.onEndSession(this);

            wl.release();
        }
        
        @Override
        public void onResume() {
        	super.onResume();

            wl.acquire();
        }
        
        @Override
        public void onStop() {
        	System.out.println("We finished tidily again");
        	super.onStop();
        }
        
        public void addEvent(String eventId, Map<String, String> parameters) {
        }
        
        public void showPapaya() {
        	System.out.println("I'm in Papaland!");
        	Intent myIntent = new Intent(AndroidGame.this,PapayaActivity.class);
        	AndroidGame.this.startActivity(myIntent);
        }

        public void showLeadBolt() {
        	System.out.println("I'm in LeadboltLand!");
        	Intent myIntent = new Intent(AndroidGame.this,LeadBoltActivity.class);
        	AndroidGame.this.startActivity(myIntent);
        }
        public void showAppCircle() {
        	System.out.println("I'm in AppCircleLand!");
        	Intent myIntent = new Intent(AndroidGame.this,AppCircleActivity.class);
        	AndroidGame.this.startActivity(myIntent);       	
        }

        // This is the callback that posts a message for the handler
        public void showAds(String type) {
        	if (type == "Papaya") {
        		showPapaya();
        	} else if (type=="Leadbolt") {
        		showLeadBolt();
        	} else if (type=="AppCircle") {
        		showAppCircle();
        	}
        }

		public void addEvent(String eventId, HashMap<String, String> event) {
        	FlurryAgent.logEvent(eventId, event);
		}
        

	
}